source = {"a": {"b": 1, "c": 2}, "d": {"e": 3, "f": {"g": 4}}}


def flatmap(src):
    def _flatmap(src, target=None, prefix=""):
        for k, v in src.items():
            if isinstance(v, (list, tuple, set, dict)):
                _flatmap(v, target=target, prefix=prefix+k+".")
            else:
                target[prefix+k] = v
    target = {}
    _flatmap(src, target=target)
    return target

if __name__ == "__main__":

    print(flatmap(source))
